<!-- 外部查看页面 -->
<template>
    <Preview :elementList="elementList" :canvas="canvas" :pageList="pageList"></Preview>
</template>

<script>
import request from '@/js/util/url.js';
import user from '@/js/util/user.js';
import message from '@/js/util/message.js';
import bus from '@/js/event/bus.js';

export default {
    data() {
        return {
            elementList: [],
            canvas: {},
            pageList: []
        };
    },
    components: {
        Preview: () => import('@/view/main/Preview.vue')
    },
    mounted() {
        if (this.$route.query.viewer && this.$route.query.viewer == '1') {
            bus.initExporePlayer({ viewer: true });
        }
        this.$nextTick(() => {
            this.initialize();
        });
    },
    methods: {
        initialize() {
            if (!this.$route.query.id) {
                return;
            }
            let tokenFlag = this.$route.query.token;
            let result = tokenFlag ? request.getTemplate({ id: this.$route.query.id, token: tokenFlag }) : request.previewGetTemplate({ id: this.$route.query.id });
            if (result.state.code === 10000) {
                let { attribute } = result.body.message;
                attribute = JSON.parse(attribute);
                this.elementList = attribute.elementList;
                this.canvas = attribute.canvas;
                this.pageList = attribute.pageList;
            } else {
                message.message(result.body.message, 'error');
            }
        }
    }
};
</script>
<style lang='scss' scoped>
</style>